home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 708 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. From: Max Welton <maxw@ix.netcom.com>
  2. Message-ID: <4i80om$2jo@ixnews3.ix.netcom.com>
  3. X-Original-Date: 14 Mar 1996 02:37:10 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 14 Mar 96 04:18:08 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: String value of enum
  9. Organization: YoYoDyne
  10. References: <4i5sf3$89c@hermes.is.co.za> <Do81tp.H9u@rsvl.unisys.com>
  11. X-Netcom-Date: Wed Mar 13  6:37:10 PM PST 1996
  12. X-Mailer: Mozilla 1.22 (Windows; I; 16bit)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBFAgUBMUeeDeEDnX0m9pzZAQFxNwF+NKucH+Z2uoVPAvoKoiq/NfkasRyK7OyA
  15.     Q5rhGoPZgOO1LnjO4WRkc8Rzo6Jv4W+u
  16.     =Up3a
  17.  
  18. mtm4@rsvl.unisys.com (Michael McCormick) wrote:
  19. >"W. Dicks" <wd@isis.co.za> shared the following on 13 Mar 96 07:31:13 GMT:
  20. >
  21. >>The system that I'm working often needs to know the string 
  22. >>value of an enum. e.g. enum week{MON=1, ..., SUN} it; it = 
  23. >>TUE;
  24. >>Then when this enum is passed as a parameter the function 
  25. >>should return the string based on the enum. For instance, 
  26. >>weekImage(it) will return "TUE". Is it not possible that such 
  27. >>a functionality can be built into enums?
  28. >
  29. >What you are essentially asking for is language support for converting
  30. >a label into a string respresentation of its name.  That is a very
  31. >unusual feature to find in any language, since it would require the
  32. >compiler to place the symbolic dictionary in the executable file.  I
  33. >don't think there's a snowball's chance of this getting into C++.
  34.  
  35. It's not _that_ unusual. Ada has had this feature starting with 
  36. Ada-83 (the 'image attribute).
  37.  
  38. Actually, I've done the above in C++ by wrapping the enum of 
  39. interest in a class, placing a static array of const strings 
  40. in the implementation-file and providing an accessor member 
  41. function that simply indexes into the array and returns the 
  42. appropriate string (or a const char* to it, anyhow).
  43. ---
  44. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  45. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  46. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  47. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  48. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  49.